<template>
    <div class="app-container">
        <el-row :gutter="20">
            <!--患者数据-->
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px"
                class="formBox1 formBox searchForm">

                <el-form-item label="医院" prop="hospital" clearable>
                    <department :isHospital="true" :isdepat="true" @refreshData="refreshData" deptWidth="160px"
                        :isUserAll="true" ref="department">
                    </department>
                </el-form-item>
                <el-form-item label="顾客ID" prop="patientId">
                    <el-input v-model="queryParams.patientId" placeholder="顾客ID" clearable style="width: 160px"
                        @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="顾客编号">
                    <el-input v-model="queryParams.visitNum" placeholder="请输入顾客编号" clearable style="width: 160px"
                        @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input v-model="queryParams.patientName" placeholder="请输入姓名" clearable style="width: 160px"
                        @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="顾客性质">
                    <el-select v-model="queryParams.properties" filterable placeholder="请选择顾客性质" clearable style="width: 160px">
                        <el-option v-for="dict in dict.type.sys_patient_properties" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="状态">
                    <el-select v-model="queryParams.status" filterable placeholder="请选择状态" clearable style="width: 160px">
                        <el-option v-for="dict in dict.type.sys_diagnosis_status" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="专病名称">
                    <el-select v-model="queryParams.diseaseClassifyName" filterable placeholder="请选择专病名称" clearable
                        style="width: 160px">
                        <el-option v-for="item in classifyList" :key="item.diseaseClassifyId"
                            :label="item.diseaseClassifyName" :value="item.diseaseClassifyName" />
                    </el-select>
                </el-form-item>

                <el-form-item label="咨询医生">
                    <el-select v-model="queryParams.consultationerUserName" filterable placeholder="请选择咨询医生" clearable
                        style="width:160px">
                        <el-option v-for="(item, index) in doctorList" :key="index" :label="item.nickName"
                            :value="item.userName"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="诊断医生">
                    <el-select v-model="queryParams.doctorUserName" filterable placeholder="请选择诊断医生" clearable
                        style="width: 160px">
                        <el-option v-for="(item, index) in DropdownList" :key="index" :label="item.nickName"
                            :value="item.userName"></el-option>
                    </el-select>
                </el-form-item>

                <!--                <el-form-item label="治疗医生">-->
                <!--                        <el-select v-model="queryParams.treatmentDoctorName" filterable placeholder="请选择治疗医生" clearable style="width: 160px">-->
                <!--                            <el-option v-for="(item,index)in treatmentDoctorUsersList" :key="index" :label="item.nickName"-->
                <!--                                :value="item.userName"></el-option>-->
                <!--                        </el-select>-->
                <!--                    </el-form-item>-->
                <el-form-item label="治疗项目">
                    <el-select v-model="queryParams.treatmentId" filterable placeholder="请选择治疗项目" clearable
                        style="width: 160px">
                        <el-option v-for="item in singlePlanList" :key="item.planId" :label="item.medicalEquipment"
                            :value="item.planId"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="评分">
                    <el-select v-model="queryParams.introducedClassifyId" placeholder="请选择" clearable
                        style="width:160px;margin-right:10px;">
                        <el-option v-for="item in introducedClassifyList" :key="item.introducedClassifyId"
                            :label="item.introducedClassifyName" :value="item.introducedClassifyId"></el-option>
                    </el-select>
                    <el-input-number v-model="queryParams.aiStartScore" controls-position="right" :min="0"
                        :disabled="!queryParams.introducedClassifyId ? true : false" style="width: 103px" />
                    ——
                    <el-input-number v-model="queryParams.aiEndScore" controls-position="right" :min="0"
                        :disabled="!queryParams.introducedClassifyId ? true : false" style="width: 103px" />
                </el-form-item>
                <!-- <el-form-item label="就诊医院">
                        <el-select v-model="queryParams.hospitalId" filterable placeholder="就诊医院" clearable
                            :disabled="deptOptionsAble" style="width: 160px">
                            <el-option v-for="item in deptOptionsArr" :key="item.deptId" :label="item.deptName"
                                :value="item.deptId"></el-option>
                        </el-select>
                    </el-form-item> -->
                <el-form-item label="登记时间">
                    <el-date-picker v-model="dateRange" style="width:240px" value-format="yyyy-MM-dd" type="daterange"
                        :picker-options="pickerOptions" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        @change="handleQuery"></el-date-picker>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>

            </el-form>
            <div class="formBox searchForm" style="margin-bottom:0px!important;" ref="statisticalTable">
                <el-row :gutter="10" class="mb8">
                    <right-toolbar :showSearch.sync="showSearch" @queryTable="handleQuery"></right-toolbar>
                </el-row>
                <el-table border v-loading="loading" :data="patientsList" @selection-change="handleSelectionChange"
                    :height="statisticalTableH" ref="table">
                    <!-- <el-table-column type="selection" width="50" align="center" /> -->
                    <el-table-column sortable label="顾客ID" align="center" prop="patientId" :show-overflow-tooltip="true"
                        width="80" />
                    <!--                    <el-table-column sortable label="顾客编号" align="center" key="visitNum" prop="visitNum" width="160" />-->
                    <el-table-column sortable label="顾客编号" align="center" prop="visitNum" width="160">
                        <template slot-scope="scope">
                            <el-tooltip placement="right" effect="light">
                                <div slot="content" v-html="renderTooltip(scope.row)" style="max-width: 700px" />
                                <span style="text-decoration: underline;color: #10a1df; ">
                                    {{ scope.row.visitNum }}
                                </span>
                            </el-tooltip>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="顾客类型" align="center" key="properties" prop="properties"
                        :show-overflow-tooltip="true" width="90">
                        <template slot-scope="scope">
                            <el-tag effect="dark" type="warning" v-if="scope.row.properties === '1'">科研</el-tag>
                            <el-tag effect="dark"  v-else-if="scope.row.properties === '2'">体检</el-tag>
                            <el-tag effect="dark" type="success" v-else>临床</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="姓名" align="center" key="patientName" prop="patientName"
                        :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <!-- <el-badge v-if="scope.row.properties === '1'" value="研" class="elbadge">
                                <span>{{ scope.row.patientName }}</span>
                            </el-badge> -->
                            <span >{{ scope.row.patientName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="就诊医院" align="center" key="hospitalId" prop="hospitalId"
                        :show-overflow-tooltip="true" width="160">
                        <template slot-scope="scope">
                            <departTag :options="deptNameLists" :value="scope.row.hospitalId" />
                        </template>
                        <!-- <template slot-scope="scope">
                            <span>{{ gethospital(scope.row.hospitalId) }}</span>
                        </template> -->
                    </el-table-column>
                    <el-table-column sortable label="就诊门诊" align="center" key="deptId" prop="deptId"
                        :show-overflow-tooltip="true" width="160">
                        <template slot-scope="scope">
                            <departTag :options="deptNameLists" :value="scope.row.deptId" />
                        </template>
                      
                    </el-table-column>
                    <el-table-column sortable label="性别" align="center" prop="sex" width="80">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="照片数量" align="center" prop="photoCount" width="100">
                        <template slot-scope="scope">
                            <el-tag  type="success" size="mini" v-if="scope.row.photoCount&&scope.row.photoCount>0">
                               {{ scope.row.photoCount }}
                            </el-tag>
                            <el-tag  type="info" size="mini" v-else>
                               {{ scope.row.photoCount }}
                            </el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="年龄" align="center" prop="age" width="80">

                    </el-table-column>
                    <el-table-column sortable label="状态" align="center" key="status" prop="status" width="120"
                        :show-overflow-tooltip="true">
                        <!--                        <template slot-scope="scope">-->
                        <!--                            <span>{{ matchDict("sys_diagnosis_status", scope.row.status) }}</span>-->
                        <!--                        </template>-->
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.status == '0'" type="danger" size="mini">
                                <dict-tag :options="dict.type.sys_diagnosis_status" :value="scope.row.status" />
                            </el-tag>
                            <el-tag v-else-if="scope.row.status == '1'" type="warning" size="mini">
                                <dict-tag :options="dict.type.sys_diagnosis_status" :value="scope.row.status" />
                            </el-tag>
                            <el-tag v-else-if="scope.row.status == '3'" type="success" size="mini">
                                <dict-tag :options="dict.type.sys_diagnosis_status" :value="scope.row.status" />
                            </el-tag>
                            <el-tag v-else-if="scope.row.status == '4'" size="mini">
                                <dict-tag :options="dict.type.sys_diagnosis_status" :value="scope.row.status" />
                            </el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="登记时间" align="center" prop="createTime" width="160">
                    </el-table-column>
                    <!--                    <el-table-column sortable label="诊断" align="left" prop="doctorDiagnosis" width="220">-->
                    <!--                        <template slot-scope="scope">-->
                    <!--                            <span v-if="scope.row.doctorDiagnosis"-->
                    <!--                                v-html="getdoctorDiagnosis(scope.row.doctorDiagnosis)"></span>-->
                    <!--                            <span v-else>&#45;&#45;</span>-->
                    <!--                        </template>-->
                    <!--                    </el-table-column>-->
                    <el-table-column sortable label="医生诊断" align="left" prop="doctorDiagnosisValue" width="220">
                        <template slot-scope="scope">
                            <span v-html="scope.row.doctorDiagnosisValue"></span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="方案" align="center" prop="doctorPlan" width="250">
                        <template slot-scope="scope">
                            <el-tooltip placement="right" effect="right" v-if="scope.row.doctorPlan">
                                <div slot="content"
                                    style="max-width: 500px;line-height:25px;font-size:16px;background:#fff;padding:15px;border:1px solid #eee;">
                                    {{ scope.row.doctorPlan }}
                                </div>
                                <div style="text-decoration: underline;color: #10a1df;overflow: hidden;
                                    white-space: nowrap;
                                    text-overflow: ellipsis;">
                                    {{ scope.row.doctorPlan }}
                                </div>
                            </el-tooltip>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <!--                    <el-table-column sortable label="登记医生" align="center" prop="createBy" width="120">-->
                    <!--                        <template slot-scope="scope">-->
                    <!--                            <span v-if="scope.row.createBy">{{ scope.row.createBy }}</span>-->
                    <!--                            <span v-else>&#45;&#45;</span>-->
                    <!--                        </template>-->
                    <!--                    </el-table-column>-->
                    <el-table-column sortable label="咨询医生" align="center" prop="consultationer" width="120">
                        <template slot-scope="scope">
                            <span v-if="scope.row.consultationer">{{ scope.row.consultationer }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="诊断医生" align="center" prop="doctor" width="120">
                        <template slot-scope="scope">
                            <span v-if="scope.row.doctor">{{ scope.row.doctor }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="AI mMASI" align="center" prop="photoMasi" width="120"
                        :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span v-if="scope.row.photoMasi">{{ scope.row.photoMasi }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="治疗项目" align="center" prop="treatmentNames" width="120"
                        :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span v-if="scope.row.treatmentNames">{{ scope.row.treatmentNames }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column sortable label="治疗医生" align="center" prop="doctor" width="120">
                    </el-table-column> -->
                    <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width"
                        fixed="right">
                        <template slot-scope="scope">
                            <!-- <el-button size="mini" type="text" @click="handleFinish(scope.row)"
                            v-hasPermi="['system:user:edit']">结束</el-button>
                        <el-button size="mini" type="text" @click="handleDelete(scope.row)"
                            v-hasPermi="['system:user:remove']">剔除</el-button> -->
                            <el-button size="mini" type="text" @click="handleDetail(scope.row)"
                                v-hasPermi="['system:patient:detail']">详情</el-button>

                        </template>
                    </el-table-column>
                </el-table>
                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getVisitList" />
            </div>
        </el-row>
        <el-dialog title="选择顾客" :visible.sync="patientVisible" width="80%" :close-on-click-modal="false" v-dialogDrag>
            <div class="formBox">
                <el-table border v-loading="loading" style="width: 100%" :data="patientList">
                    <el-table-column label="序号" align="center" type="index" width="50">
                        <template slot-scope="scope">
                            <span>{{ getIndex0(scope.$index) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="顾客编号" align="center" prop="visitNum" width="160" />
                    <el-table-column sortable label="顾客姓名" align="center" prop="patientName" :show-overflow-tooltip="true"
                        width="100" />
                    <el-table-column sortable label="顾客手机号" align="center" prop="patientPhone" :show-overflow-tooltip="true"
                        width="120" />
                    <el-table-column sortable label="顾客身份证号" align="center" prop="idNum" :show-overflow-tooltip="true"
                        width="180" />
                    <el-table-column sortable label="性别" align="center" prop="sex" width="80">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="年龄" align="center" prop="birthDate" width="80">
                        <template slot-scope="scope">
                            <span>{{ parseInt((new Date() - new Date(parseTime(scope.row.birthDate))) / (1000 * 60 * 60 * 24
                                * 365))
                            }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="就诊门诊" align="center" prop="deptName" :show-overflow-tooltip="true"
                        width="160" />

                    <el-table-column sortable label="状态" align="center" prop="status" :show-overflow-tooltip="true"
                        width="120">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_diagnosis_status" :value="scope.row.status" />
                        </template>
                    </el-table-column>
                    <!--            <el-table-column sortable label="卡号" align="center" prop="cardNumber" :show-overflow-tooltip="true" />-->

                    <el-table-column sortable label="顾客性质" align="center" prop="properties" width="100">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_patient_properties" :value="scope.row.properties" />
                        </template>
                    </el-table-column>
                    <!--            <el-table-column sortable label="顾客分类" align="center" prop="customerSort" width="100">-->
                    <!--              <template slot-scope="scope">-->
                    <!--                <dict-tag :options="dict.type.sys_patient_sort" :value="scope.row.customerSort" />-->
                    <!--              </template>-->
                    <!--            </el-table-column>-->
                    <!--            <el-table-column label="诊断" align="center" prop="diagnosis" />-->

                    <el-table-column sortable label="登记人" align="center" prop="createBy" width="100"
                        :show-overflow-tooltip="true" />
                    <el-table-column sortable label="登记日期" align="center" prop="createTime" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.createTime) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width"
                        width="100">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-caret-right"
                                @click="confirmPatient(scope.row)">点击选择</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <pagination v-show="listTotal > 0" :total="listTotal" :pageSizes.sync="pageSizes"
                    :page.sync="queryListParams.pageNum" :limit.sync="queryListParams.pageSize"
                    @pagination="getPatientList" />
            </div>
        </el-dialog>
        <el-dialog :title="detailTitle" :visible.sync="detailDialogVisible" :width="device !== 'mobile' ? '85%' : '100%'"
            v-dialogDrag class="nopaddingDailog" :class="device !== 'mobile' ? '' : 'active'" :close-on-click-modal="false">
            <CustomerDetails v-if="detailDialogVisible" :basicInfo="basicInfo"></CustomerDetails>
        </el-dialog>
    </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getListUser, listUser } from "@/api/system/user";
import {
    listPatientAll
} from "@/api/patients/patient";
import {
    listPlan,
} from "@/api/system/plan";
import {
    listClassify,
} from "@/api/system/classify";

import {
    listVisitTip, getVisit
} from "@/api/patientRegistration/registrationList"; //列表接口
import { addressJson } from "@/api/patients/personal";
import { getToken } from "@/utils/auth";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import PatientDetail from "./patientDetail.vue";
import AddVisitDialog from "./addVisitDialog.vue";
import CustomerDetails from "@/views/components/customerDetail/customerDetail";
import department from "@/views/components/department/index.vue";
import departTag from "@/views/components/department/departTag.vue";
import { listDept, deptNameList } from "@/api/system/dept";
export default {
    name: "patientList",
    components: { PatientDetail, AddVisitDialog, CustomerDetails, department, departTag },
    dicts: [
        "sys_normal_disable",
        "sys_manage_diseases",
        "sys_diagnosis_status",
        "sys_user_category",
        "sys_user_sex",

        "sys_patient_properties",
        "sys_skin_tone",
        "sys_patient_sort",
        "sys_outpatient_clinic",
        "sys_general_questionnaire",
        "sys_patient_reason",
    ],
    data() {
        return {
            statisticalTableH: undefined,
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() > Date.now() - 8.64e6;  //如果没有后面的-8.64e6就是不可以选择今天的
                },
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        const end = date;
                        const start = date;
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '前天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 2);
                        const end = date;
                        const start = date;
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近六个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近1年',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            treatmentDoctorUsersList: [],//治疗医生
            detailTitle: "",
            detailDialogVisible: false,
            basicInfo: {},
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            listTotal: 0,
            // 患者表格数据
            patientsList: null,
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            // 表单参数
            form: { avatar: "" },

            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                diseaseId: undefined,

                status: undefined,
                visitNum: undefined,
                patientName: undefined,
                properties:undefined,
                visitUserName: undefined,
                doctorUserName: undefined,
                // treatmentDoctorName: undefined,
                consultationerUserName: undefined,
                treatmentId: undefined,
                introducedClassifyId: "0",
                aiStartScore: undefined,
                aiEndScore: undefined,
                hospitalId: undefined,

            },
            queryListParams: {
                pageNum: 1,
                pageSize: 5,
                visitNum: undefined,
                patientName: undefined,
            },
            patientList: [],
            patientItem: {},
            // 顾客选择弹窗
            patientVisible: false,
            pageSizes: [5, 10, 15, 20],
            // 表单校验
            rules: {
                diseaseId: [
                    {
                        required: true,
                        message: "患者名称不能为空",
                        trigger: "blur",
                    },
                ],
                diseaseClassifyName: [
                    {
                        required: true,
                        message: "患者分类不能为空",
                        trigger: "blur",
                    },
                ],
            },
            classifyList: [],
            introducedClassifyList: [
                {
                    introducedClassifyId: "0",
                    introducedClassifyName: "AI mMASI",
                }
            ],
            doctorList: [],
            DropdownList: [],
            singlePlanList: [],
            deptOptionsArr: [],//医院
            deptOptionsAble: false,
            deptNameLists: []
        };
    },
    mounted() {
        this.changeHeight()
    },
    watch: {
        showSearch() {
            this.$nextTick(() => {
                this.changeHeight()
            }, 1000)

        }
    },
    created() {
        this.getClassifyList();
        this.getTreatmentDoctorUsersList();
        this.getDoctorList();
        this.getDoctorData();
        this.getSinglePlanList();

    },
    updated() {
        this.$nextTick(() => {
            this.$refs.table.doLayout()
        })
    },
    computed: {
        ...mapGetters(["dept", "hospital", "device"]),
    },
    methods: {
        changeHeight() {
            if (this.$refs.statisticalTable) {
                const statisticalTableObj = this.$refs.statisticalTable.getBoundingClientRect();
                let h = statisticalTableObj.top + 100
                this.statisticalTableH = 'calc(100vh - ' + h + 'px)'
            } else {
                this.statisticalTableH = '500px'
            }
        },
        renderTooltip(row) {
            return `<div style="margin-bottom:5px;font-size:20px;color:#1890ff;"><span style="font-weight:bold;"> 顾客状态：</span>${this.matchDict("sys_diagnosis_status", row.status)}</div>
        <div style="width: 100%;height:1px;background-color: red;margin-bottom:5px;"></div>
        <div style="margin-bottom:5px;font-size:18px"><span style="margin-right:10px;"><span style="font-weight:bold;">登记日期：</span>${this.parseTime(row.createTime)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">登记人：</span>${this.formatValue(row.createBy)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">就诊科室：</span>${this.formatValue(row.deptName)}</span> </div>
        <div style="margin-bottom:5px;font-size:18px"><span style="margin-right:10px;"><span style="font-weight:bold;">顾客性质：</span>${this.matchDict("sys_patient_properties", row.properties)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">顾客分类：</span>${this.matchDict("sys_patient_sort", row.customerSort)}</span></div>
        <div style="margin-bottom:5px;font-size:18px"><span style="font-weight:bold;">地址：</span>${this.formatValue(row.address)}</div>
        <div style="margin-bottom:5px;font-size:18px"><span style="font-weight:bold;">电话：</span>${this.formatValue(row.patientPhone)}</div>
        <div style="width: 100%;height:1px;background-color: red;margin-bottom:5px;"></div>
        <div style="margin-bottom:5px;font-size:18px"><span style="margin-right:10px;"><span style="font-weight:bold;">通用问卷：</span>${this.matchDict("sys_general_questionnaire", row.questionnaireStatus)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">专病问卷：</span>${this.formatValue(row.diseaseQuestionnaireStatus)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">照片：</span>${this.formatValue(row.photoCount)}</span></div>
        <div style="margin-bottom:5px;font-size:18px"><span style="margin-right:10px;"><span style="font-weight:bold;">咨询日期：</span>${this.formatValue(row.consultationTime)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">咨询医生：</span>${this.formatValue(row.consultationer)}</span></div>
        <div style="margin-bottom:5px;font-size:18px"><span style="font-weight:bold;">咨询诊断：</span>${this.formatValue(row.consultationDiagnosis)}</div>
        <div style="margin-bottom:5px;font-size:18px"><span style="font-weight:bold;">咨询方案：</span>${this.formatValue(row.consultationPlan)}</div>
        <div style="margin-bottom:5px;font-size:18px"><span style="margin-right:10px;"><span style="font-weight:bold;">方案总额：</span>${this.formatValue(row.consultationTotalExpenses)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">治疗费用：</span>${this.formatValue(row.consultationTreatmentExpenses)}</span></div>
        <div style="width: 100%;height:1px;background-color: red;margin-bottom:5px;"></div>
        <div style="margin-bottom:5px;font-size:18px"><span style="margin-right:10px;"><span style="font-weight:bold;">诊断日期：</span>${this.formatValue(row.doctorTime)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">诊断医生：</span>${this.formatValue(row.doctor)}</span></div>
        <div style="margin-bottom:5px;font-size:18px"><span style="font-weight:bold;">医生诊断：</span>${this.formatValue(row.doctorDiagnosis)}</div>
        <div style="margin-bottom:5px;font-size:18px"><span style="font-weight:bold;">医生方案：</span>${this.formatValue(row.doctorPlan)}</div>
        <div style="margin-bottom:5px;font-size:18px"><span style="margin-right:10px;"><span style="font-weight:bold;">方案总额：</span>${this.formatValue(row.doctorTotalExpenses)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">治疗费用：</span>${this.formatValue(row.doctorTreatmentExpenses)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">复诊次数：</span>${this.formatValue(row.reviewNum)}</span></div>
        <div style="width: 100%;height: 1px;background-color: red;margin-bottom:5px;"></div>
        <div style="margin-bottom:5px;font-size:18px"><span style="margin-right:10px;"><span style="font-weight:bold;">知情同意书：</span>${this.formatValue(row.informedConsent)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">确费状态：</span>${this.formatValue(row.confirmExpense == '1' ? '已确费' : '未确费')}</span><span style="margin-right:10px;"><span style="font-weight:bold;">治疗次数：</span>${this.formatValue(row.treatmentTimes)}</span><span style="margin-right:10px;"><span style="font-weight:bold;">温馨提示：</span>${this.formatValue(row.tipsTimes)}</span></div>`
        },
        formatValue(value) {
            if (value == null) {
                return ''
            } else {
                return value
            }
        },
        /** id转化成对应的文字 */
        matchDict: function (key, id) {
            let _this = this;
            const result = _this.dict.type[key];
            let textValue = "";
            result.forEach((item) => {
                if (item.raw.dictValue == id) {
                    textValue = item.raw.dictLabel;
                }
            });
            return textValue;
        },
        refreshData(data) {
            this.queryParams.pageNum = 1;
            this.queryParams.hospitalId = data.hospitalId
            this.queryParams.deptId = data.deptId

            this.refreshList()
        },
        refreshList() {
            this.getSinglePlanList()
            this.getTreatmentDoctorUsersList();
            this.getDoctorList();
            this.getDoctorData();
            this.queryParams.doctorUserName = undefined
            this.queryParams.treatmentId = undefined
            this.queryParams.consultationerUserName = undefined
            //     pageNum: 1,
            //     pageSize: 10,
            //     diseaseId: undefined,
            //     status: undefined,
            //     visitNum: undefined,
            //     patientName: undefined,
            //     visitUserName: undefined,
            //     doctorUserName: undefined,
            //     consultationerUserName: undefined,
            //     treatmentId: undefined,
            //     introducedClassifyId: "0",
            //     aiStartScore: undefined,
            //     aiEndScore: undefined,
            //     hospitalId: this.queryParams.hospitalId,
            // }
            this.getdeptNameList()
        },
        // 回显医院及门诊
        getdeptNameList() {
            deptNameList().then((response) => {
                this.deptNameLists = response.data;
                this.getVisitList();
            });
        },

        // getdoctorDiagnosis(string) {
        //     let obj = JSON.parse(string)
        //     // console.log(obj)
        //     let Htmlstr = ''
        //     if (obj && obj.length > 0) {
        //         obj.forEach(function (item, index) {
        //             let diagnosis = item.diagnosis
        //             let diagnosisArr = diagnosis.split('、')
        //             let diagnosisStr = diagnosisArr[0] + '(' + diagnosisArr.slice(1, diagnosisArr.length) + ')'
        //             Htmlstr += diagnosisStr + '<br/>'
        //         });
        //         return Htmlstr //obj[0].diagnosis
        //     } else {
        //         return ''
        //     }
        // },
        getIndex0(index) {
            return (this.queryListParams.pageNum - 1) * this.queryListParams.pageNum + index + 1;
        },
        /** 治疗项目 */
        getSinglePlanList() {
            listPlan({
                pageNum: 1,
                pageSize: 9999,
                status: 0,
                hospitalId: this.queryParams.hospitalId,
                planCategoryId: "2"
            }).then(
                (response) => {
                    this.singlePlanList = response.rows;
                }
            );
        },

        // 获取专病列表
        getClassifyList() {
            listClassify(
                {
                    pageNum: 1,
                    pageSize: 9999,
                    status: '0'
                }
            ).then((response) => {
                this.classifyList = response.rows;
            });
        },
        /** 查询咨询医生 */
        getDoctorData() {
            getListUser({ funcRole: '1', hospitalId: this.queryParams.hospitalId }).then((response) => {
                if (response.code == 200) {
                    this.doctorList = response.data
                }
            });
        },
        //查询诊断医生列表
        getDoctorList() {
            getListUser({ funcRole: '2', hospitalId: this.queryParams.hospitalId }).then((response) => {
                if (response.code == 200) {
                    this.DropdownList = response.data
                }
            });
        },
        //查询治疗医生列表
        getTreatmentDoctorUsersList() {
            getListUser({ funcRole: '3', hospitalId: this.queryParams.hospitalId }).then((response) => {
                if (response.code == 200) {
                    this.treatmentDoctorUsersList = response.data
                }
            });

        },

        /** 查询就诊列表 */
        getVisitList() {
            this.loading = true;
            // this.queryParams.visitNum = this.patientItem.visitNum
            listPatientAll(this.addDateRange(this.queryParams, this.dateRange)).then(
                (response) => {
                    if (response.code == 200) {
                        this.patientsList = response.rows;
                        this.patientsList.forEach((item) => {
                            if (item.parentId) {
                                item.visitStatus = 2;
                            } else {
                                item.visitStatus = 1;
                            }

                            if (item.consultationDiagnosis.includes(';')) {
                                let Mobject = ''
                                item.consultationDiagnosis.split(';').forEach(it => {
                                    Mobject += it + '<br>'
                                })
                                item.consultationDiagnosisValue = Mobject
                            } else {
                                item.consultationDiagnosisValue = item.consultationDiagnosis
                            }
                            if (item.doctorDiagnosis.includes(';')) {
                                let MobjectDoctor = ''
                                item.doctorDiagnosis.split(';').forEach(it => {
                                    MobjectDoctor += it + '<br>'
                                })
                                item.doctorDiagnosisValue = MobjectDoctor
                            } else {
                                item.doctorDiagnosisValue = item.doctorDiagnosis
                            }

                        });

                        this.total = response.total;
                    }

                    this.loading = false;
                }
            );
        },


        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.queryListParams.pageNum = 1;
            this.getVisitList();
            // if (this.queryParams.visitNum || this.queryParams.patientName) {
            //     this.queryListParams.visitNum = this.queryParams.visitNum
            //     this.queryListParams.patientName = this.queryParams.patientName
            //     this.getPatientList();
            // } else {
            //     this.getVisitList();
            // }
        },
        /** 重置按钮操作 */
        resetQuery() {
            let hospitalId = this.queryParams.hospitalId
            this.queryParams = {
                pageNum: 1,
                pageSize: 10,
                diseaseId: undefined,
                status: undefined,
                visitNum: undefined,
                patientName: undefined,
                visitUserName: undefined,
                doctorUserName: undefined,
                consultationerUserName: undefined,
                treatmentId: undefined,
                introducedClassifyId: "0",
                aiStartScore: undefined,
                aiEndScore: undefined,
                properties:undefined,
                hospitalId: this.queryParams.hospitalId,
            }
            this.queryListParams = {
                pageNum: 1,
                pageSize: 5,
                visitNum: undefined,
                patientName: undefined,
            }
            this.dateRange = []
            this.patientItem = {}

            console.log(hospitalId)
            this.resetForm("queryForm");
            if (this.getSplit(this.dept.ancestors).length == 3 || this.getSplit(this.dept.ancestors).length == 2) {
                this.queryParams.hospitalId = hospitalId
            } else {
                this.queryParams.hospitalId = undefined
            }

            this.handleQuery();
        },
        getSplit(str) {
            return str.split(',')
        },
        // 多选框选中数据
        handleSelectionChange(selection) {

        },
        /** 详情按钮操作 */
        handleDetail(row) {
            this.detailTitle = "顾客详情";
            this.basicInfo = row;
            this.detailDialogVisible = true;
        },
        // 获取顾客登记列表
        getPatientList() {
            getVisit(this.queryListParams).then(
                (response) => {
                    if (response.rows.length > 0) {
                        if (response.rows.length == 1) {
                            this.patientItem = response.rows[0];
                            this.patientItem.birthDate = parseInt((new Date() - new Date(this.parseTime(this.patientItem.birthDate))) / (1000 * 60 * 60 * 24 * 365))
                            //顾客列表
                            this.queryParams.visitNum = this.patientItem.visitNum
                            this.getVisitList();
                        } else {
                            this.loading = true
                            this.patientVisible = true
                            this.patientList = response.rows;
                            this.patientList.forEach(item => {
                                item.birthDate = parseInt((new Date() - new Date(this.parseTime(this.patientList.birthDate))) / (1000 * 60 * 60 * 24 * 365))
                            })

                            this.listTotal = response.total;
                            this.loading = false;
                        }
                    } else {
                        // this.$modal.msgWarning("没找到对应的顾客！");
                        this.$confirm('没找到对应的顾客！请您自己搜索选择顾客', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        })
                            .then((content) => {
                                this.resetQuery()
                                console.log('content', content)
                            })
                            .catch((error) => {
                                this.resetQuery()
                                console.log('error', error)
                            })
                    }
                }
            )
        },
        confirmPatient(row) {
            this.patientItem = row
            this.patientVisible = false
            this.queryParams.visitNum = this.patientItem.visitNum
            this.getVisitList();
        },
    },
};
</script>

<style scoped rel="stylesheet/scss"  lang="scss">
.el-input-number--small {
    width: 110px;
}

.elbadge {
    margin-top: 10px;
}
</style>
